<?
load_model('Common');
class Comment extends Common {
	protected $_name ="comment";
	protected $_primary = 'com_id';
	
	public function get_comment_list($where=null,$order='com_id desc',$count=null,$offset=null){
		$arr = $this->fetchAll($where,$order,$count,$offset)->toArray();
		return $arr;
	}
	
	public function get_tencom(){
		$db = $this->getAdapter();
		$sql = "select * from zf_comment order by com_date desc limit 10";
		return $db->fetchAll($sql);
	}
	
	public function get_comment_by_art($art_id){
		$arr = $this->fetchAll("com_art_id=$art_id","com_id desc")->toArray();
		return $arr;
	}
	
	public function get_comment_by_pho($pho_id){
		$arr = $this->fetchAll("com_pho_id=$pho_id","com_id desc")->toArray();
		return $arr;
	}
	
	public function get_comment_by_class_pho($cid){
		$arr = $this->fetchAll("com_pho_id=$cid","com_id desc")->toArray();
		return $arr;
	}
	
	public function get_comment_info($id){
		$db = $this->getAdapter();
		$where = $db->quoteInto('com_id = ?', $id);
		return $this->fetchRow($where)->toArray();
	}
	/**
	 * 根据where获取指定字段信息
	 *
	 * @param unknown_type $field
	 * @param unknown_type $where
	 * @return string/int 
	 */
	function get_com_one($field,$where){
		$db = $this->getAdapter();
		$sql = "select $field from zf_comment where $where";
		return $db->fetchOne($sql);
	}
	
	/**
	 *
	 * @param unknown_type $data
	 * @return 返回刚插入的id
	 */
	function add_comment($data){
		$dataInsert = array(
		    'com_art_id' => $data['com_art_id'],
		    'com_pho_id' => $data['com_pho_id'],
		    'com_writer' => $data['com_writer'],
		    'com_content'=> $data['com_content'],
		    'com_date'   => $data['com_date'],
		    'com_ip'	 => GetIP(),
		);
		return $this->insert($dataInsert);
	}
	
	function update_com($id, $data){
		$db = $this->getAdapter();
		$where = $db->quoteInto('com_id = ?', $id);
		return $this->update($data, $where);
	}
	
	function del_com($id){
		$db = $this->getAdapter();
		$where = $db->quoteInto('com_id = ?', $id);
		return $this->delete($where);
	}
	
	public function del_com_by_artid($art_id){
		$db = $this->getAdapter();
		$sql = "delete from zf_comment where com_art_id='$art_id'";
		$db -> query($sql);
	}
	public function del_com_by_phoid($pho_id){
		$db = $this->getAdapter();
		$sql = "delete from zf_comment where ta_pho_id='$pho_id'";
		$db -> query($sql);
	}
	
}

?>